package com.example.controller;

import com.example.entity.User;
import com.example.service.UserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author 叶凯乐
 */
@Controller
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class UserController {

    @Resource
    UserServiceImpl userService;

    @PostMapping("/recieve")
    @ResponseBody
    public ArrayList<HashMap<String,String>>recieve(String adminId,String userId){
        return userService.recieveMessage(adminId,userId);
    }

    @PostMapping( "/userLogin")
    @ResponseBody
    public boolean login(String userId,String password){
        return userService.doLogin(userId,password)!=null;
    }
    @PostMapping("/updatePassword")
    @ResponseBody
    public int alterPassword(String olderPassword, String newPassword,String userId){
        return userService.changePassword(userId,olderPassword,newPassword);
    }

    @PostMapping("/watchUsernames")
    @ResponseBody
    public ArrayList<String>watchUsernames(String userId){
        return userService.listClassUsers(userId);
    }

    @PostMapping("/watchAdminName")
    @ResponseBody
    public String getAdminName(String userId){
        return userService.getAdminName(userId);
    }
    @PostMapping("/watchAllMessage")
    @ResponseBody
    public ArrayList<User>listAll(String userId){
        return userService.watchAll(userId);
    }
}
